package com.fita.admin.entity.search.data;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

import java.util.Map;

public class LocationSearch implements QueryBuilder {
	
	private String name;
	
	private String cityName;
	
	private String country;
	
	private String supplier;
	
	private String code;
	
	private String airportCode;
	
	private QueryFilter filter;
	
	private QueryOrder order;
	
	public LocationSearch() {
		order = new QueryOrder();
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
		
		if (filter == null || refresh) {
			
			filter = new QueryFilter();
			
			filter.addLike("name", name);
			
			filter.addLike("cityName", cityName);
			
			filter.addEquals("country", country);
			
			filter.addLike("code", code);
			
			filter.addLike("airportCode", airportCode);
			
			filter.addLike("supplier", supplier);
		}
		
		return filter;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {
		
		String sentence = "FROM Location Where disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		
        return sentence;
	}

	/* (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
	 */
	public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the cityName
	 */
	public String getCityName() {
		return cityName;
	}

	/**
	 * @param cityName the cityName to set
	 */
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	/**
	 * @return the country
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * @param country the country to set
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @return the airportCode
	 */
	public String getAirportCode() {
		return airportCode;
	}

	/**
	 * @param airportCode the airportCode to set
	 */
	public void setAirportCode(String airportCode) {
		this.airportCode = airportCode;
	}

	/**
	 * @return the supplier
	 */
	public String getSupplier() {
		return supplier;
	}

	/**
	 * @param supplier the supplier to set
	 */
	public void setSupplier(String supplier) {
		this.supplier = supplier;
	}
	
}
